# coding:utf-8
# 5.1.1 创建列表
# number = [1,2,3,4,5]
# mix = [1,"小甲鱼",3.14,[1,2,3]]
# empty = []


# 5.1.2 列表添加元素
number = [1, 2, 3, 4, 5]
number.append(6)
# print (number)

# number.append(7,8)
# number.extend(7,8)
number.extend([7, 8])

# print (number)

number.insert(1, 0)
# print (number)

number.insert(0, 0)
# print (number)


# 5.1.3 从列表中获取元素
name = ["鸡蛋", "鸭蛋", "鹅蛋", "李狗蛋"]
# print (name [0])
# print (name [3])
name[1], name[2] = name[3], name[1]
# print (name)


# 5.1.4 从列表删除元素
name.remove("李狗蛋")
# print (name)

del name[1]
# print (name)

# del name
# print (name)

name = ["鸡蛋", "鸭蛋", "鹅蛋", "李狗蛋"]
# print (name.pop())
# print (name.pop())
# print (name.pop())
# print (name.pop(2))


# 5.1.5 列表分切
name = ["鸡蛋", "鸭蛋", "鹅蛋", "李狗蛋"]
# print (name[0:2])
# print (name[:2])
# print (name[1:])
# print (name[:])
# print (name[-1:])
# print (name[:-1])

# 5.1.6 列表分片的进阶玩法
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# print (list1[0:9:2])
# print (list1[::2])
# print (list1[::-1])


# 5.1.7 一些常用操作符
list1 = [123]
list2 = [234]
# print (lis1 > lis2)

list3 = ['abc']
list4 = ['bcd']
# print (list3<list4)

list1 = [123, 456]
list2 = [234, 123]
list3 = list1 + list2
# print (list3)

list1 = [123]
# print(list1 * 3)

# list1 * = 5
list1 = list1 * 5
# print(list1)

list1 = ["小猪", "小猫", "小狗", "小甲鱼"]
# print("小甲鱼" in list1)
# print ("小护士" not in list1)

list1 = ["小猪", "小猫", ["小甲鱼", "小护士"], "小狗"]
# print ("小甲鱼" in list1)
# print ("小护士" not in list1)
# print (list1[2][0])

# print (dir(list))

list1 = [1, 1, 2, 3, 5, 8, 13, 21]
# print (list1.count(1))
# print (list1.index(1))

start = list1.index(1) + 1
stop = len(list1)
# print (list1.index(1,start,stop))

list1 = [1, 2, 3, 4, 5, 6, 7, 8]
list1.reverse()
# print (list1)

list1 = [8, 9, 3, 5, 2, 6, 10, 1, 0]
list1.sort()
# print (list1)

list1 = [8, 9, 3, 5, 2, 6, 10, 1, 0]
list1.sort(reverse=True)
# print (list1)

# 5.1.9 关于分片“拷贝”概念的补充
list1 = [1,3,2,7,8,9]
list2 = list1[:]
list3 = list1
# print (list2)
# print (list3)
list1.sort()
# print (list1)
# print (list2)
# print (list3)
# 注意：为一个列表指定另一个名字的做法，只是向同一个列表增加一个新的标签而已，真正的拷贝是要使用分片的方法
